<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <input type="text" v-model="formData.name">
        <input type="radio" v-model="formData.sex" value="1">男
        <input type="radio" v-model="formData.sex" value="2">女
    </div>
    <script src="../vue.js"></script>
    <script>
        new Vue({
            el:'#app',
            data () {
                return {
                    formData:{
                        'name':'',
                        'sex':1,
                    }
                }
            },
            watch: {
                formData:{
                    handler(newVal,oldVal){
                        console.log(newVal);
                        for (const key in newVal) {
                            if (!newVal[key]) {
                                console.log(key+'值为空!');
                            }
                        }
                    },
                    deep:true,  //深度监听（数组和对象要用）
                    immediate:true,  //立即执行
                }
            }
        })
    </script>
</body>
</html>